package com.base.andlangcore.util

import android.content.Context
import android.content.pm.PackageInfo
import android.content.pm.PackageManager

/**
 * 基础工具类
 */
class BaseLangUtils {
    companion object {
        /**
         * 获取VerionName
         *
         * @param context
         * @return
         */
        fun getVersionName(context: Context): String {
            var packInfo: PackageInfo? = null
            try {
                val packageManager = context.packageManager
                packInfo = packageManager.getPackageInfo(
                    context.packageName,
                    0
                )
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }
            return packInfo!!.versionName
        }

        /**
         * 获取VerionCode
         *
         * @param context
         * @return
         */
        fun getVersionCode(context: Context): Int {
            var packInfo: PackageInfo? = null
            try {
                val packageManager = context.packageManager
                packInfo = packageManager.getPackageInfo(
                    context.packageName,
                    0
                )
            } catch (e: PackageManager.NameNotFoundException) {
                e.printStackTrace()
            }
            return packInfo!!.versionCode
        }

        fun isEmpty(str: String?): Boolean {
            return str == null || str.isEmpty()
        }
    }
}